package com.roger.match.library;

import com.roger.match.library.util.AttrUtils;
import com.roger.match.library.util.MatchView;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.AttrSet;
import ohos.agp.components.element.ShapeElement;
import ohos.agp.utils.Color;
import ohos.agp.utils.TextTool;
import ohos.app.Context;


/**
 * Description:MatchTextView
 * User: Lj
 * Date: 2014-12-03
 * Time: 10:48
 * FIXME
 */
public class MatchTextView extends MatchView {
    String mContent;
    float mTextSize;
    int mTextColor;
    private int DEF_INDETERMINATE_COLOR = Color.WHITE.getValue();

    /**
     * 初始化
     *
     * @param context context
     */
    public MatchTextView(Context context) {
        super(context);
        init();
    }

    /**
     * 初始化
     *
     * @param context context
     * @param attrs attrs
     */
    public MatchTextView(Context context, AttrSet attrs) {
        super(context, attrs);
        mTextSize = AttrUtils.getDimensionValueByAttr(attrs, "textSize",25);
        mTextColor = AttrUtils.getColorValueByAttr(attrs, "textColor",new Color(DEF_INDETERMINATE_COLOR)).getValue();
        mContent = AttrUtils.getStringValueByAttr(attrs, "text","text");
        init();
    }

    /**
     * 初始化
     *
     * @param context context
     * @param attrs attrs
     * @param defStyleAttr defStyleAttr
     */
    public MatchTextView(Context context, AttrSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    void init() {
        ShapeElement shapeElement = new ShapeElement();
        shapeElement.setRgbColor(new RgbColor(Color.TRANSPARENT.getValue()));
        this.setBackground(shapeElement);
        if (!TextTool.isNullOrEmpty(mContent)) {
            setTextColor(mTextColor);
            setTextSize(mTextSize);
            initWithString(mContent);
            show();
        }
    }

    /**
     * 设置文字
     *
     * @param text text
     */
    public void setText(String text) {
        this.mContent = text;
        init();
    }
}
